﻿namespace HRM.CORE
{
    using DevExpress.Utils;
    using DevExpress.XtraEditors;
    using DevExpress.XtraEditors.Controls;
    using DevExpress.XtraTab;
    using APP.HELPER;
    using Common.Class; using APP.HELPER.Utils.Language; using Security.Security; using Dictionary.ERP;
    using HRM.CORE;
    using System; using Extra.ERP;
    using System.ComponentModel;
    using System.Drawing;
    using System.Runtime.CompilerServices;
    using System.Windows.Forms; using Common;
    using Security.ERP;

    public class xucRewardAdd : Common.xucBaseAddH
    {
        private CalcEdit calTotalValue;
        private TextEdit cboDecideNumber;
        private ComboBoxEdit cboLevel;
        private TextEdit cboPerson;
        private ComboBoxEdit cboStatus;
        private IContainer components = null;
        private DateEdit dtDate;
        private DateEdit dtDecideDate;
        private LabelControl labelControl1;
        private LabelControl labelControl10;
        private LabelControl labelControl11;
        private LabelControl labelControl12;
        private LabelControl labelControl2;
        private LabelControl labelControl3;
        private LabelControl labelControl31;
        private LabelControl labelControl4;
        private LabelControl labelControl5;
        private LabelControl labelControl6;
        private LabelControl labelControl7;
        private LabelControl labelControl8;
        private LabelControl labelControl9;
        private MemoEdit txtForm;
        private MemoEdit txtFoundation;
        private TextEdit txtID;
        private MemoEdit txtObject;
        private MemoEdit txtReason;
        private TextEdit txtSource;
        private XtraTabControl xtraTabControl1;
        private XtraTabPage xtraTabPage1;

        public event SuccessEventHander Success;

        public xucRewardAdd()
        {
            this.InitializeComponent();
            this.InitComponent();
        }

        protected override void Add()
        {
            base.Add();
            this.txtID.Text = new HRM_REWARD().NewID();
            this.txtFoundation.Focus();
        }

        public void Clear()
        {
            this.InitComponent();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        protected override void Init()
        {
        }

        private void InitComponent()
        {
            this.cboStatus.SelectedIndex = 0;
            this.dtDate.DateTime = System.DateTime.Now;
            this.dtDecideDate.DateTime = System.DateTime.Now;
            this.calTotalValue.EditValue = 0;
        }

        private void InitializeComponent()
        {
            ComponentResourceManager manager = new ComponentResourceManager(typeof(xucRewardAdd));
            this.xtraTabControl1 = new XtraTabControl();
            this.xtraTabPage1 = new XtraTabPage();
            this.labelControl8 = new LabelControl();
            this.dtDate = new DateEdit();
            this.labelControl7 = new LabelControl();
            this.labelControl4 = new LabelControl();
            this.calTotalValue = new CalcEdit();
            this.labelControl3 = new LabelControl();
            this.txtSource = new TextEdit();
            this.dtDecideDate = new DateEdit();
            this.labelControl2 = new LabelControl();
            this.labelControl5 = new LabelControl();
            this.labelControl6 = new LabelControl();
            this.cboDecideNumber = new TextEdit();
            this.cboPerson = new TextEdit();
            this.labelControl12 = new LabelControl();
            this.labelControl31 = new LabelControl();
            this.txtObject = new MemoEdit();
            this.labelControl11 = new LabelControl();
            this.labelControl10 = new LabelControl();
            this.labelControl9 = new LabelControl();
            this.cboStatus = new ComboBoxEdit();
            this.txtReason = new MemoEdit();
            this.txtFoundation = new MemoEdit();
            this.labelControl1 = new LabelControl();
            this.txtID = new TextEdit();
            this.txtForm = new MemoEdit();
            this.cboLevel = new ComboBoxEdit();
            ((ISupportInitialize) base.Err).BeginInit();
            base.imageCollection2.BeginInit();
            this.xtraTabControl1.BeginInit();
            this.xtraTabControl1.SuspendLayout();
            this.xtraTabPage1.SuspendLayout();
            this.dtDate.Properties.VistaTimeProperties.BeginInit();
            this.dtDate.Properties.BeginInit();
            this.calTotalValue.Properties.BeginInit();
            this.txtSource.Properties.BeginInit();
            this.dtDecideDate.Properties.VistaTimeProperties.BeginInit();
            this.dtDecideDate.Properties.BeginInit();
            this.cboDecideNumber.Properties.BeginInit();
            this.cboPerson.Properties.BeginInit();
            this.txtObject.Properties.BeginInit();
            this.cboStatus.Properties.BeginInit();
            this.txtReason.Properties.BeginInit();
            this.txtFoundation.Properties.BeginInit();
            this.txtID.Properties.BeginInit();
            this.txtForm.Properties.BeginInit();
            this.cboLevel.Properties.BeginInit();
            base.SuspendLayout();
            base.btnSave.Location = new Point(0x115, 0x183);
            base.btnSave.TabIndex = 1;
            base.btnCancel.Location = new Point(0x1dd, 0x183);
            base.btnCancel.TabIndex = 3;
            base.btnSaveNew.Location = new Point(0x178, 0x183);
            base.btnSaveNew.TabIndex = 2;
            base.imageCollection2.ImageStream = (ImageCollectionStreamer) manager.GetObject("imageCollection2.ImageStream");
            this.xtraTabControl1.Dock = DockStyle.Top;
            this.xtraTabControl1.HeaderButtons = TabButtons.Default | TabButtons.Next | TabButtons.Prev;
            this.xtraTabControl1.HeaderButtonsShowMode = TabButtonShowMode.Always;
            this.xtraTabControl1.ImeMode = ImeMode.NoControl;
            this.xtraTabControl1.Location = new Point(0, 2);
            this.xtraTabControl1.Name = "xtraTabControl1";
            this.xtraTabControl1.SelectedTabPage = this.xtraTabPage1;
            this.xtraTabControl1.Size = new Size(0x249, 0x17a);
            this.xtraTabControl1.TabIndex = 0;
            this.xtraTabControl1.TabPages.AddRange(new XtraTabPage[] { this.xtraTabPage1 });
            this.xtraTabPage1.Controls.Add(this.labelControl8);
            this.xtraTabPage1.Controls.Add(this.dtDate);
            this.xtraTabPage1.Controls.Add(this.labelControl7);
            this.xtraTabPage1.Controls.Add(this.labelControl4);
            this.xtraTabPage1.Controls.Add(this.calTotalValue);
            this.xtraTabPage1.Controls.Add(this.labelControl3);
            this.xtraTabPage1.Controls.Add(this.txtSource);
            this.xtraTabPage1.Controls.Add(this.dtDecideDate);
            this.xtraTabPage1.Controls.Add(this.labelControl2);
            this.xtraTabPage1.Controls.Add(this.labelControl5);
            this.xtraTabPage1.Controls.Add(this.labelControl6);
            this.xtraTabPage1.Controls.Add(this.cboDecideNumber);
            this.xtraTabPage1.Controls.Add(this.cboPerson);
            this.xtraTabPage1.Controls.Add(this.labelControl12);
            this.xtraTabPage1.Controls.Add(this.labelControl31);
            this.xtraTabPage1.Controls.Add(this.txtObject);
            this.xtraTabPage1.Controls.Add(this.labelControl11);
            this.xtraTabPage1.Controls.Add(this.labelControl10);
            this.xtraTabPage1.Controls.Add(this.labelControl9);
            this.xtraTabPage1.Controls.Add(this.cboStatus);
            this.xtraTabPage1.Controls.Add(this.txtReason);
            this.xtraTabPage1.Controls.Add(this.txtFoundation);
            this.xtraTabPage1.Controls.Add(this.labelControl1);
            this.xtraTabPage1.Controls.Add(this.txtID);
            this.xtraTabPage1.Controls.Add(this.txtForm);
            this.xtraTabPage1.Controls.Add(this.cboLevel);
            this.xtraTabPage1.Name = "xtraTabPage1";
            this.xtraTabPage1.Size = new Size(0x242, 0x15d);
            this.xtraTabPage1.Text = "Th\x00f4ng tin khen thưởng";
            this.labelControl8.Appearance.Options.UseTextOptions = true;
            this.labelControl8.Appearance.TextOptions.WordWrap = WordWrap.Wrap;
            this.labelControl8.AutoSizeMode = LabelAutoSizeMode.None;
            this.labelControl8.Location = new Point(0xaf, 0x135);
            this.labelControl8.Name = "labelControl8";
            this.labelControl8.Size = new Size(60, 30);
            this.labelControl8.TabIndex = 0x17;
            this.labelControl8.Text = "Cấp khen thưởng:";
            this.dtDate.EditValue = null;
            this.dtDate.Location = new Point(0x1b2, 0x13b);
            this.dtDate.Name = "dtDate";
            this.dtDate.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo) });
            this.dtDate.Properties.VistaTimeProperties.Buttons.AddRange(new EditorButton[] { new EditorButton() });
            this.dtDate.Size = new Size(0x7f, 20);
            this.dtDate.TabIndex = 0;
            this.labelControl7.Appearance.Options.UseTextOptions = true;
            this.labelControl7.Appearance.TextOptions.WordWrap = WordWrap.Wrap;
            this.labelControl7.AutoSizeMode = LabelAutoSizeMode.None;
            this.labelControl7.Location = new Point(13, 0x138);
            this.labelControl7.Name = "labelControl7";
            this.labelControl7.Size = new Size(0x3e, 0x16);
            this.labelControl7.TabIndex = 0x15;
            this.labelControl7.Text = "Tổng gi\x00e1 trị:";
            this.labelControl4.Location = new Point(0x14f, 0x13e);
            this.labelControl4.Name = "labelControl4";
            this.labelControl4.Size = new Size(0x5d, 13);
            this.labelControl4.TabIndex = 0x19;
            this.labelControl4.Text = "Ng\x00e0y khen thưởng:";
            this.calTotalValue.Location = new Point(80, 0x13b);
            this.calTotalValue.Name = "calTotalValue";
            this.calTotalValue.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo) });
            this.calTotalValue.Size = new Size(90, 20);
            this.calTotalValue.TabIndex = 0x16;
            this.labelControl3.Location = new Point(12, 0xf3);
            this.labelControl3.Name = "labelControl3";
            this.labelControl3.Size = new Size(0x33, 13);
            this.labelControl3.TabIndex = 13;
            this.labelControl3.Text = "Nguồn chi:";
            this.txtSource.Location = new Point(0x51, 0xf1);
            this.txtSource.Name = "txtSource";
            this.txtSource.Size = new Size(0x1df, 20);
            this.txtSource.TabIndex = 14;
            this.dtDecideDate.EditValue = null;
            this.dtDecideDate.Location = new Point(0xff, 0x113);
            this.dtDecideDate.Name = "dtDecideDate";
            this.dtDecideDate.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo) });
            this.dtDecideDate.Properties.VistaTimeProperties.Buttons.AddRange(new EditorButton[] { new EditorButton() });
            this.dtDecideDate.Size = new Size(0x59, 20);
            this.dtDecideDate.TabIndex = 0x12;
            this.labelControl2.Appearance.Options.UseTextOptions = true;
            this.labelControl2.Appearance.TextOptions.WordWrap = WordWrap.Wrap;
            this.labelControl2.AutoSizeMode = LabelAutoSizeMode.None;
            this.labelControl2.Location = new Point(12, 0x10d);
            this.labelControl2.Name = "labelControl2";
            this.labelControl2.Size = new Size(0x38, 30);
            this.labelControl2.TabIndex = 15;
            this.labelControl2.Text = "Số quyết định:";
            this.labelControl5.Location = new Point(0xad, 0x115);
            this.labelControl5.Name = "labelControl5";
            this.labelControl5.Size = new Size(0x4d, 13);
            this.labelControl5.TabIndex = 0x11;
            this.labelControl5.Text = "Ng\x00e0y ban h\x00e0nh:";
            this.labelControl6.Location = new Point(350, 0x115);
            this.labelControl6.Name = "labelControl6";
            this.labelControl6.Size = new Size(80, 13);
            this.labelControl6.TabIndex = 0x13;
            this.labelControl6.Text = "Người ban h\x00e0nh:";
            this.cboDecideNumber.Location = new Point(0x51, 0x112);
            this.cboDecideNumber.Name = "cboDecideNumber";
            this.cboDecideNumber.Size = new Size(0x59, 20);
            this.cboDecideNumber.TabIndex = 0x10;
            this.cboPerson.Location = new Point(0x1b2, 0x112);
            this.cboPerson.Name = "cboPerson";
            this.cboPerson.Size = new Size(0x7f, 20);
            this.cboPerson.TabIndex = 20;
            this.labelControl12.Location = new Point(0xc6, 0x19);
            this.labelControl12.Name = "labelControl12";
            this.labelControl12.Size = new Size(0x35, 13);
            this.labelControl12.TabIndex = 3;
            this.labelControl12.Text = "Trạng th\x00e1i:";
            this.labelControl31.Appearance.Options.UseTextOptions = true;
            this.labelControl31.Appearance.TextOptions.WordWrap = WordWrap.Wrap;
            this.labelControl31.AutoSizeMode = LabelAutoSizeMode.None;
            this.labelControl31.Location = new Point(13, 140);
            this.labelControl31.Name = "labelControl31";
            this.labelControl31.Size = new Size(0x3d, 0x2a);
            this.labelControl31.TabIndex = 9;
            this.labelControl31.Text = "Đối tượng khen thưởng:";
            this.txtObject.Location = new Point(0x51, 0x92);
            this.txtObject.Name = "txtObject";
            this.txtObject.Size = new Size(0x1df, 0x24);
            this.txtObject.TabIndex = 10;
            this.labelControl11.Appearance.Options.UseTextOptions = true;
            this.labelControl11.Appearance.TextOptions.WordWrap = WordWrap.Wrap;
            this.labelControl11.AutoSizeMode = LabelAutoSizeMode.None;
            this.labelControl11.Location = new Point(13, 0xbf);
            this.labelControl11.Name = "labelControl11";
            this.labelControl11.Size = new Size(0x3e, 0x2c);
            this.labelControl11.TabIndex = 11;
            this.labelControl11.Text = "H\x00ecnh thức khen thưởng:";
            this.labelControl10.Appearance.Options.UseTextOptions = true;
            this.labelControl10.Appearance.TextOptions.WordWrap = WordWrap.Wrap;
            this.labelControl10.AutoSizeMode = LabelAutoSizeMode.None;
            this.labelControl10.Location = new Point(14, 0x65);
            this.labelControl10.Name = "labelControl10";
            this.labelControl10.Size = new Size(0x3d, 0x1c);
            this.labelControl10.TabIndex = 7;
            this.labelControl10.Text = "L\x00fd do khen thưởng:";
            this.labelControl9.Appearance.Options.UseTextOptions = true;
            this.labelControl9.Appearance.TextOptions.WordWrap = WordWrap.Wrap;
            this.labelControl9.AutoSizeMode = LabelAutoSizeMode.None;
            this.labelControl9.Location = new Point(14, 0x38);
            this.labelControl9.Name = "labelControl9";
            this.labelControl9.Size = new Size(0x3e, 0x1d);
            this.labelControl9.TabIndex = 5;
            this.labelControl9.Text = "Căn cứ khen thưởng:";
            this.cboStatus.EditValue = "L\x00ean kế hoạch";
            this.cboStatus.Location = new Point(0x103, 0x15);
            this.cboStatus.Name = "cboStatus";
            this.cboStatus.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo) });
            this.cboStatus.Properties.Items.AddRange(new object[] { "L\x00ean kế hoạch", "Đang thực hiện", "Đ\x00e3 thực hiện" });
            this.cboStatus.Size = new Size(0x12d, 20);
            this.cboStatus.TabIndex = 4;
            this.txtReason.Location = new Point(0x51, 0x63);
            this.txtReason.Name = "txtReason";
            this.txtReason.Size = new Size(0x1df, 0x24);
            this.txtReason.TabIndex = 8;
            this.txtFoundation.Location = new Point(0x51, 0x36);
            this.txtFoundation.Name = "txtFoundation";
            this.txtFoundation.Size = new Size(480, 0x24);
            this.txtFoundation.TabIndex = 6;
            this.labelControl1.Appearance.Options.UseTextOptions = true;
            this.labelControl1.Appearance.TextOptions.WordWrap = WordWrap.Wrap;
            this.labelControl1.AutoSizeMode = LabelAutoSizeMode.None;
            this.labelControl1.Location = new Point(14, 20);
            this.labelControl1.Name = "labelControl1";
            this.labelControl1.Size = new Size(0x3d, 0x1a);
            this.labelControl1.TabIndex = 1;
            this.labelControl1.Text = "M\x00e3 đợt khen thưởng (*):";
            this.txtID.Location = new Point(0x51, 0x15);
            this.txtID.Name = "txtID";
            this.txtID.Size = new Size(0x6a, 20);
            this.txtID.TabIndex = 2;
            this.txtID.EditValueChanged += new EventHandler(this.txtID_EditValueChanged);
            this.txtForm.Location = new Point(80, 0xc1);
            this.txtForm.Name = "txtForm";
            this.txtForm.Size = new Size(0x1e1, 0x24);
            this.txtForm.TabIndex = 12;
            this.cboLevel.Location = new Point(240, 0x13a);
            this.cboLevel.Name = "cboLevel";
            this.cboLevel.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo) });
            this.cboLevel.Size = new Size(0x59, 20);
            this.cboLevel.TabIndex = 0x18;
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.Controls.Add(this.xtraTabControl1);
            base.Name = "xucRewardAdd";
            base.Padding = new Padding(0, 2, 0, 0);
            base.Size = new Size(0x249, 0x1a7);
            base.Controls.SetChildIndex(base.btnSaveNew, 0);
            base.Controls.SetChildIndex(base.btnSave, 0);
            base.Controls.SetChildIndex(base.btnCancel, 0);
            base.Controls.SetChildIndex(this.xtraTabControl1, 0);
            ((ISupportInitialize) base.Err).EndInit();
            base.imageCollection2.EndInit();
            this.xtraTabControl1.EndInit();
            this.xtraTabControl1.ResumeLayout(false);
            this.xtraTabPage1.ResumeLayout(false);
            this.xtraTabPage1.PerformLayout();
            this.dtDate.Properties.VistaTimeProperties.EndInit();
            this.dtDate.Properties.EndInit();
            this.calTotalValue.Properties.EndInit();
            this.txtSource.Properties.EndInit();
            this.dtDecideDate.Properties.VistaTimeProperties.EndInit();
            this.dtDecideDate.Properties.EndInit();
            this.cboDecideNumber.Properties.EndInit();
            this.cboPerson.Properties.EndInit();
            this.txtObject.Properties.EndInit();
            this.cboStatus.Properties.EndInit();
            this.txtReason.Properties.EndInit();
            this.txtFoundation.Properties.EndInit();
            this.txtID.Properties.EndInit();
            this.txtForm.Properties.EndInit();
            this.cboLevel.Properties.EndInit();
            base.ResumeLayout(false);
        }

        private void RaiseSuccessEventHander(HRM_REWARD item)
        {
            if (this.Success != null)
            {
                this.Success(this, item);
            }
        }

        public void SetData(HRM_REWARD item)
        {
            this.txtID.Text = item.RewardCode;
            SYS_LOG.Insert("Khen Thưởng", "Xem", this.txtID.Text);
            if (base.m_Status == Actions.Update)
            {
                this.txtID.Properties.ReadOnly = true;
            }
            this.cboStatus.SelectedIndex = item.Status;
            this.txtFoundation.Text = item.Foundation;
            this.txtReason.Text = item.Reason;
            this.txtObject.Text = item.Object;
            this.txtForm.Text = item.Form;
            this.txtSource.Text = item.Source;
            this.dtDate.DateTime = item.Date;
            this.calTotalValue.EditValue = item.TotalValue;
            this.cboDecideNumber.Text = item.DecideNumber;
            this.dtDecideDate.DateTime = item.DecideDate;
            this.cboPerson.Text = item.Person;
            this.cboLevel.Text = item.Level;
        }

        private void txtID_EditValueChanged(object sender, EventArgs e)
        {
            TextEdit control = (TextEdit) sender;
            if (control.ErrorText != string.Empty)
            {
                base.Err.SetError(control, string.Empty);
            }
            if (base.m_Status == Actions.Add)
            {
                HRM_REWARD hrm_reward = new HRM_REWARD();
                if (hrm_reward.Exist(control.Text))
                {
                    base.Err.SetError(control, "M\x00e3 đ\x00e3 tồn tại.");
                    control.Focus();
                }
            }
        }

        protected override string uc_Change()
        {
            return string.Empty;
        }

        protected override string uc_Delete()
        {
            HRM_REWARD item = new HRM_REWARD {
                RewardCode = this.txtID.Text
            };
            string str = item.Delete();
            if (str == "OK")
            {
                this.RaiseSuccessEventHander(item);
            }
            return str;
        }

        protected override string uc_Save()
        {
            if (MyRule.Get(MyLogin.RoleId, "bbiReward") != "OK")
            {
                return "";
            }
            if (!MyRule.AllowAdd)
            {
                MyRule.Notify();
                return "";
            }
            SYS_LOG.Insert("Khen Thưởng", "Th\x00eam", this.txtID.Text);
            base.SetWaitDialogCaption("Đang lưu dữ liệu...");
            Cursor.Current = Cursors.WaitCursor;
            HRM_REWARD item = new HRM_REWARD {
                RewardCode = this.txtID.Text,
                Status = this.cboStatus.SelectedIndex,
                Foundation = this.txtFoundation.Text,
                Reason = this.txtReason.Text,
                Object = this.txtObject.Text,
                Form = this.txtForm.Text,
                Source = this.txtSource.Text,
                TotalValue = decimal.Parse(this.calTotalValue.EditValue.ToString()),
                Date = this.dtDate.DateTime,
                DecideNumber = this.cboDecideNumber.Text,
                DecideDate = this.dtDecideDate.DateTime,
                Person = this.cboPerson.Text,
                Level = this.cboLevel.Text
            };
            string text = item.Insert();
            if (text == "OK")
            {
                this.RaiseSuccessEventHander(item);
            }
            Cursor.Current = Cursors.Default;
            this.DoHide();
            if (text != "OK")
            {
                XtraMessageBox.Show(text, "Cảnh B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            return text;
        }

        protected override string uc_Update()
        {
            if (MyRule.Get(MyLogin.RoleId, "bbiReward") != "OK")
            {
                return "";
            }
            if (!MyRule.AllowEdit)
            {
                MyRule.Notify();
                return "";
            }
            base.SetWaitDialogCaption("Đang cập nhật dữ liệu...");
            HRM_REWARD item = new HRM_REWARD {
                RewardCode = this.txtID.Text,
                Status = this.cboStatus.SelectedIndex,
                Foundation = this.txtFoundation.Text,
                Reason = this.txtReason.Text,
                Object = this.txtObject.Text,
                Form = this.txtForm.Text,
                Source = this.txtSource.Text,
                TotalValue = decimal.Parse(this.calTotalValue.EditValue.ToString()),
                Date = this.dtDate.DateTime,
                DecideNumber = this.cboDecideNumber.Text,
                DecideDate = this.dtDecideDate.DateTime,
                Person = this.cboPerson.Text,
                Level = this.cboLevel.Text
            };
            string text = item.Update();
            if (text == "OK")
            {
                this.RaiseSuccessEventHander(item);
            }
            if (text != "OK")
            {
                XtraMessageBox.Show(text, "Cảnh B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            this.DoHide();
            return text;
        }

        public delegate void SuccessEventHander(object sender, HRM_REWARD item);
    }
}

